package com.jiefeng.manage.web.controller.dataexcel;

import com.jiefeng.manager.service.dataexcel.DataExcelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by WuZhiqi on 2016/5/30.
 */
@Controller
public class ObjectDataExcelTemplateCtrl {

    private static final Logger logger = LoggerFactory.getLogger(ObjectDataExcelTemplateCtrl.class);

    /**
     * 匹配数据Excel模板导出
     * @param response
     */
    @RequestMapping("matchedDataExcelTemplate2")
    public void exportExcel(HttpServletResponse response) {
        response.setContentType("application/vnd.ms-excel");
        SimpleDateFormat yyyyMMddHHmmss = new SimpleDateFormat("yyyyMMddHHmmss");
        String fileName = "MatchedData_ExcelImportTemplate_" + yyyyMMddHHmmss.format(new Date()) + ".xls";
        response.setHeader("content-disposition", "attachment;filename=" + fileName);
        try{
            OutputStream outputStream = response.getOutputStream();
            DataExcelService<Object> dataExcelService = DataExcelService.getInstance(Object.class);
            dataExcelService.exportExcelTemplate(outputStream, DataExcelService.EXCEL_VERSION.VERSION_XLS);
        }catch (Exception e){
            logger.error("导出匹配数据Excel模板异常!", e);
        }
    }
}
